<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('OKR项目管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目编码：</label>
                                <input type="text" name="code"/>
                            </li>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>公司主体：</label>
                                <input type="text" name="company"/>
                            </li>
                            <li>
                                <label>项目阶段：</label>
                                <select name="stage" th:with="type=${@dict.getType('okr_project_stage')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:project:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:project:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:project:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:project:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-success" onclick="batchAddRole()">
                    <i class="fa fa-plus"></i> 项目赋权
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:project:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:project:remove')}]];
        var stageDatas = [[${@dict.getType('okr_project_stage')}]];
        var statusDatas = [[${@dict.getType('row_status')}]];
        var prefix = ctx + "system/project";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "OKR项目管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: '主键',
                    visible: false
                },
                {
                    field: 'code', 
                    title: '项目编码'
                },
                {
                    field: 'name', 
                    title: '项目名称'
                },
                {
                    field: 'company', 
                    title: '公司主体'
                },
                {
                    field: 'status', 
                    title: '数据状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        //批量添加项目管理员
        function batchAddRole(){
            var selectRows = $.table.selectRowData();
            console.log(selectRows);
            if(selectRows.length>0)
            {
                var url =  ctx + "okr/info/selectProjectUser/"+ getProjectIds(selectRows);
                $.modal.openFull("选择协同用户", url);
            }
            else {
                $.modal.alertError("请至少选择一条数据..");
            }
        }

        //用js
        function getProjectIds(dataArr) {
            var str = "";
            for (var i = 0; i < dataArr.length; i++) {
                str += dataArr[i].id+ ",";
            }
            //去掉最后一个逗号(如果不需要去掉，就不用写)
            if (str.length > 0) {
                str = str.substr(0, str.length - 1);
            }
            return str;
        }
    </script>
</body>
</html>